<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/09/0009
 * Time: 17:10
 */

namespace app\sports_admin\controller;

use app\sports_admin\model\VideoType as VideoTypeModel;
use app\sports_admin\service\VideoType as VideoTypeService;
use think\Request;
use app\sports_admin\model\Cat;
use app\exception\ExceptionHandle;

class VideoType extends Base
{
    /*
     * 视频类别首页
     */
    public function index()
    {
        $data = Cat::select();
        return view('index',compact('data'));
    }
    /**
     * 更改分类名称
     */
    public function updateTypeInfo(Request $request)
    {
        if($request->isAjax()){
            $data = Cat::updateTypeInfo();
            if(!$data){
                return json([
                    'msg'=>'更改失败',
                    'errorCode'=>'400']);
            }
            return json(['code'=>201,'msg'=>'更改成功']);
        }
    }
    /*
     * 添加子类页面
     */
    public function add()
    {
        // pid 父类id  title父类名称  path路径
        $data = Request::instance()->only(['pid','title','path']);
        return view('add',compact('data'));
    }
    /*
     * 添加子类
     */
    public function insertChildren(Request $request)
    {
        if($request->isAjax()){
            return VideoTypeService::insertChildren();
        }
    }
    /*
     * 添加父类页面
     */
    public function parent()
    {
        return view('parent');
    }
    /*
    * 添加父类信息
    */
    public function insertParent(Request $request)
    {
        if($request->isAjax()){
            return VideoTypeService::insertParent();
        }
    }
    /*
     * 编辑类别信息
     * $id 类别信息id
     */
    public function edit()
    {
        $id = input('get.id');
        $data = VideoTypeModel::getFindInfo($id);
        return view('edit',compact('data'));
    }
    /*
     * 修改类别信息
     */
    public function update(Request $request)
    {
        if($request->isAjax()){
            return VideoTypeService::update();
        }
    }
    /*
     * 删除类别信息
     */
    public function deleteTypeInfo(Request $request)
    {
        if($request->isAjax()){
            $data = Cat::deleteTypeInfo();
            if(!$data){
                return json([
                    'msg'=>'删除失败',
                    'errorCode'=>'400']);
            }
            return json(['code'=>201,'msg'=>'删除成功']);
        }
    }
    /**
     * 添加类别
     */
    public function addTypeInfo(Request $request)
    {
        if($request->isAjax()){
            $data = Cat::addTypeInfo();
            if(!$data){
                return json([
                    'msg'=>'添加失败',
                    'errorCode'=>'400']);
            }
            return json(['code'=>201,'msg'=>'添加成功']);
        }
    }

}